/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package controller;

import java.io.*;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.swing.JOptionPane;
import movie.Film;
import com.oreilly.servlet.MultipartRequest;

/**
 *
 * @author Toshiba
 */
public class tambahVideo extends HttpServlet {

    /**
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        Film pkt = new Film();

        MultipartRequest vid = new MultipartRequest(request, request.getRealPath("/data"), 1024 * 1024 * 1024);

        String nama = vid.getParameter("judul");
        String sinopsis = vid.getParameter("keterangan");
        String lokasi = vid.getOriginalFileName("filevideo");
        String trailer = vid.getParameter("trailer");
        String poster =  vid.getOriginalFileName("poster");
        String harga = vid.getParameter("harga");


        try {
            pkt.setNama_film(nama);
            pkt.setSinopsisFilm(sinopsis);
            pkt.setLokasiFilm(lokasi);
            pkt.setTrailer(trailer);
            pkt.setHarga(harga);
            pkt.setPoster(poster);
            pkt.insertVideo();
            request.setAttribute("message", "Film berhasil diupload");
            request.getRequestDispatcher("/uploadvideo.jsp").forward(request, response);
        } catch (NumberFormatException ex) {
//                JOptionPane.showMessageDialog(null, "data video gagal disimpan/n"+ex.getMessage());
            request.setAttribute("message", "Gagal mengupload film");
            request.getRequestDispatcher("/uploadvideo.jsp").forward(request, response);
        }
    }
//        RequestDispatcher rd = request.getRequestDispatcher("lihatPaketAdmin.jsp");
//        rd.forward(request, response);

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /**
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        processRequest(request, response);
    }

    /**
     * Returns a short description of the servlet.
     */
    public String getServletInfo() {
        return "Short description";
    }
    // </editor-fold
}
